﻿using System.Collections.Generic;
using System.Linq;
using XSerialization.Generator;

namespace XSerialization.Templates
{
    public partial class InterfaceFileTemplate
    {
        /// <summary>
        /// List of interface declarations
        /// </summary>
        public IList<XsdComplexType> Interfaces { get; set; }

        /// <summary>
        /// List of enums declarations
        /// </summary>
        public IList<XsdEnumerationType> Enums { get; set; }

        /// <summary>
        /// Meta Informations
        /// </summary>
        public IFileMetaInfo MetaInfo { get; set; }

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="interfaces">Interface declarations</param>
        /// <param name="enums">Enum declarations</param>
        /// <param name="metaInfo">Meta Informations</param>
        public InterfaceFileTemplate(IList<XsdComplexType> interfaces, IList<XsdEnumerationType> enums, IFileMetaInfo metaInfo)
        {
            Interfaces = interfaces;
            Enums = enums;
            MetaInfo = metaInfo;

            bool contains = MetaInfo.Usings.Any(item => item == "System.Collections.Generic");
            if (!contains) MetaInfo.Usings.Add("System.Collections.Generic");
        }

        /// <summary>
        /// Returns Interface Template
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public string GetInterfaceTemplate(XsdComplexType item)
        {
            InterfaceTemplate interfaceTemplate = new InterfaceTemplate(item, MetaInfo);
            return interfaceTemplate.TransformText();
        }

        /// <summary>
        /// Returns Enumeration Template
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public string GetEnumTemplate(XsdEnumerationType item)
        {
            EnumTemplate enumTemplate = new EnumTemplate(item);
            return enumTemplate.TransformText();
        }
    }
}
